// view/fenlei/fenlxq/fenlxq.js
let proListToTop = [],
  menuToTop = [],
  MENU = 0,
  windowHeight, timeoutId;
let app = getApp()
let yuming = app.globalData.yuming;
const request = require('../../config/request');
Page({
  /**
   * 页面的初始数据
   */
  ...request,
  data: {
    gap: 0,
    yuming: yuming,
    heights: '',
    title: '商品详情',
    // background: [yuming + 'static/applet/images/dui/ba1.png', yuming +'static/applet/images/dui/ba2.png', yuming +'static/applet/images/dui/ba3.png', yuming +'static/applet/images/dui/ba4.png'],
    background: [],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    currentSwiper: 0,
    biaoqian: ['产品好 123', '拍摄清晰 565', '安装方便 365', '下次还来 227', '价格低 125', '价性比高 444'],
    pj: [{
      stars: 5,
      fen: '5.00'
    }, {
      stars: 2,
      fen: '2.00'
    }, {
      stars: 3,
      fen: '3.00'
    }, {
      stars: 4,
      fen: '4.00'
    }, {
      stars: 5,
      fen: '5.00'
    }],
    caryou: [{}, {}, {}],
    gg_left: ['品牌', '重量'],
    gg_righ: ['盯盯拍', '0.322'],
    ffcs: [{
        name: '品牌',
        con: '盯盯拍'
      },
      {
        name: '重量',
        con: '0.322'
      },
      {
        name: '型号',
        con: 'mini'
      },
      {
        name: '主镜头光圈',
        con: 'F2.2'
      },
      {
        name: '影像分辨率',
        con: '1080p'
      },
      {
        name: '拍照像素',
        con: '200万'
      },
      {
        name: '摄像像素',
        con: '200万'
      },
      {
        name: '运行内存',
        con: '64MB'
      },
      {
        name: '页面视角',
        con: '130°'
      },
      {
        name: '镜头数量',
        con: '单镜头'
      },
      {
        name: '屏幕尺寸',
        con: '无屏幕'
      },
      {
        name: '颜色分类',
        con: '黑'
      },
      {
        name: '记录仪质保',
        con: '1年'
      },
      {
        name: '内存卡质保',
        con: '3个月'
      },
    ],
    toufl: ['商品', '评价9999+', '规格', '详情'],
    touindex: 0,
    fenlei: false,
    toView: 'shangpin',
    gou: false,
    gwcc: ['标配（无卡无停车监控线）', '标配+雷克沙32G卡', '标配+雷克沙64G卡', '标配+雷克沙32G卡+降压线', '标配+雷克沙64G+降压线', '标配+雷克沙64G卡+停车监控线'],
    gwccindex: 0,
    gwff: ['行车记录仪单镜头安装|￥20.00', '无需服务'],
    ggffindex: 0,
    num: 1,
    zp: false,
    // zps: [{
    //     tit: '全正品',
    //     con: '各大厂商，直接供货'
    //   },
    //   {
    //     tit: '7天无理由退货',
    //     con: '消费者在满足7天无理由退货申请条件的前提下，可以提出“7天无理由退货”申请，退回运费由消费者承担'
    //   },
    //   {
    //     tit: '放心购',
    //     con: '知名品牌，正规授权，售后无忧'
    //   },
    //   {
    //     tit: '快送达',
    //     con: '全国各大仓库就近发货，快速送达'
    //   },
    //   {
    //     tit: '正规发票',
    //     con: '确保开出正规有效发票'
    //   },
    // ],
    id: '',
    spDetail: ''
  },
  getspXq() {
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    let that = this;
    this.myRequest(yuming + 'shop/scan_pay_goodsinfo', {
      id: that.data.id,
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.hideLoading();
        let arr = []
        arr.push(res.data.data.goods_images)
        this.setData({
          spDetail: res.data.data, //商品详情
          background: arr
        })
        this.data.spDetail.content = res.data.data.content.replace(
            /<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig,
            '<p')
          .replace(/<p>/ig, '<p style="font-size:0px">')
          .replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
          .replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
          .replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
          .replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
          .replace(/<img([\s\w"-=\/\.:;]+)/ig, '< img style="width: 380px;" $1');
        this.setData({
          spDetail: res.data.data, //商品详情
        })
      }
    })
  },
  ljgm() {
    wx.navigateTo({
      url: '/my_other/dingdan/dingdan?id=' + this.data.id,
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0,
    })
  },
  // 放大
  fangda(e) {
    var img = e.currentTarget.dataset.img
    var list = e.currentTarget.dataset.list
    var arr = []
    for (let i in list) {
      arr.push(list[i]); //属性
    }
    wx.previewImage({
      current: img,
      urls: arr
    })
  },
  // 减
  jian() {
    var num = this.data.num
    if (num == 1) {
      console.log(11)
      this.setData({
        num: 1
      })
    }
    if (num >= 1) {
      num--
      this.setData({
        num
      })
    }
  },
  // 加
  jia() {
    var num = this.data.num
    num++
    this.setData({
      num
    })
  },
  // 购物尺寸选择
  gwccxz(e) {
    var index = e.currentTarget.dataset.index
    this.setData({
      gwccindex: index
    })
  },
  // 购物服务选择
  gwfwxz(e) {
    var index = e.currentTarget.dataset.index
    this.setData({
      ggffindex: index
    })
  },
  // 加入购物车
  goucar() {
    this.setData({
      gou: true
    })
  },
  // 点击遮罩 隐藏商品选择
  gouyin() {
    this.setData({
      gou: false
    })
  },

  // 正品
  zp() {
    this.setData({
      zp: true
    })
  },
  zpyin() {
    this.setData({
      zp: false
    })
  },


  // 点击上边跳转对应内容
  changeMenu(e) {
    var index = e.currentTarget.dataset.index
    this.setData({
      touindex: index
    })
    var order = ['shangpin', 'pingjia', 'guige', 'spxq']
    // console.log(order[index+1])
    this.setData({
      toView: order[index]
    })
  },
  scroll(e) {
    // console.log(e)
    // 滑动改变亮值
    var scrollTop = e.detail.scrollTop
    if (scrollTop < this.data.pjtop) {
      this.setData({
        touindex: 0
      })
    }
    if (scrollTop > this.data.pjtop && scrollTop < this.data.ggtop) {
      this.setData({
        touindex: 1
      })
    }
    if (scrollTop > this.data.ggtop && scrollTop < this.data.spxqtop) {
      this.setData({
        touindex: 2
      })
    }
    if (scrollTop > this.data.spxqtop) {
      this.setData({
        touindex: 3
      })
    }
    // 滑动指定位置出现头部分类
    if (scrollTop > this.data.xinxitop) {
      this.setData({
        fenlei: true
      })
      this.ani = wx.createAnimation({
        duration: 1000,
        timingFunction: "liner"
      })
      this.ani.left(50).top(50).step()
    } else {
      this.setData({
        fenlei: false
      })
    }
    this.setData({
      scrollTop: scrollTop
    })
  },
  // 多组放大
  fangda(e) {
    var img = e.currentTarget.dataset.img
    var list = e.currentTarget.dataset.list
    wx.previewImage({
      current: img,
      urls: list
    })
  },
  // 单张放大
  fd(e) {
    var img = e.currentTarget.dataset.img
    wx.previewImage({
      urls: [img]
    })
  },
  // swiper 监听事件
  swiperChange: function (e) {
    this.setData({
      currentSwiper: e.detail.current
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      id: options.id
    })
    this.getspXq();
    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    wx.getSystemInfo({
      success: (res) => {
        let statusBarHeight = res.statusBarHeight,
          navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2; //导航高度
        this.setData({
          navHeight: navHeight - 5,
          gap: 200,
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this
    const query = wx.createSelectorQuery()
    // console.log(query)
    // query.select('.pingjia').boundingClientRect(res => {
    //   // console.log(res)
    //   that.setData({
    //     pjtop: res.top - 200
    //   })
    // }).exec();
    // query.select('.guige').boundingClientRect(res => {
    //   // console.log(res)
    //   that.setData({
    //     ggtop: res.top - 200
    //   })
    // }).exec();
    // query.select('.tedian').boundingClientRect(res => {
    //   // console.log(res)
    //   that.setData({
    //     spxqtop: res.top - 200
    //   })
    // }).exec();
    // query.select('.spxx').boundingClientRect(res => {
    //   // console.log(res)
    //   that.setData({
    //     xinxitop: res.top - 100
    //   })
    // }).exec();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})